###########################################################################
#
# Parameters
#

contrib 	= ../contrib
umPath   = $(contrib)/UMinhoHaskellSoftware/src
sfLib    = $(contrib)/StrategyLib-5.0
sfModel  = drift-default
sfPath   = $(sfLib)/library:$(sfLib)/models/$(sfModel)
shPath   = $(contrib)/Sdf2Haskell-2.3/generator
atLib    = $(contrib)/haterm-1.5
atPath   = $(atLib)/library
huPath   = $(contrib)/HUnit-1.0
haxml    = $(contrib)/HaXml-1.12/src
hsPath  	= :$(libs):$(sfPath):$(shPath):$(atPath):$(huPath):$(haxml):$(umPath)

# Don't lose generated Haskell files after make finishes
.PRECIOUS: *.hs


###########################################################################
#
# Targets to compile 
#

all: compile
compile: XsdMetz

###########################################################################
#
# Compilation with GHC
#

GHC     = ghc
GHCOPTS = -threaded                     \
          -fglasgow-exts                \
          -fallow-overlapping-instances \
          -fallow-undecidable-instances \
          -i${hsPath}                   \
          -hidir hidir                  \
          -odir odir

%: %.hs ${wildcard *.hs *.lhs} tmpdirs
	${GHC} -cpp ${GHCOPTS} --make $*.hs -o $@
	
# Creates folders to hold temporary compiled files
tmpdirs:
	mkdir -p odir
	mkdir -p hidir

ghci:
	ghci -O -cpp ${GHCOPTS} XsdMetz.hs

###########################################################################
#
# Cleaning supoerfluous files
#

.PHONY: clean
clean:
	-@rm -rvf XsdMetz

very-clean: clean
	-@rm -rvf hidir odir

###########################################################################
#
# Distribution
#

distName        = XsdMetz
distVersion     = $(shell date "+%Y.%m.%d")
distFiles	= README TODO Makefile $(wildcard *.hs) doc/ 
distFullName	= $(distName)-$(distVersion)

dist:
	@echo "Creating distribution $(distFullName)"
	@rm -rf $(distFullName)
	@mkdir -p $(distFullName)
	@cp -R $(distFiles) $(distFullName)
	@zip -q -r $(distFullName).zip $(distFullName)
	@tar zcf $(distFullName).tgz $(distFullName)
	@rm -rf $(distFullName)
	@echo "  READY for distribution:"
	@echo "    $(distFullName).zip"
	@echo "    $(distFullName).tgz"

###########################################################################
#
# Debugging
#

echo-%:
	@echo $($*)

###########################################################################
